﻿#pragma once
#pragma pack(push)
#pragma pack(1)


///////////////////////////////////////////////////////
#define ios_version
//comment this if you are using in Windows

///////////////////////////////////////////////////////
#define MSGVERSION '_FYW'
#define BUFFERSIZE 1024*10
///////////////////////////////////////////////////////
typedef enum
{
	hNull,
	hchLogin,				//客户端进入程序 进行登录验证
	hhcLoginSuccess,		//用户登录成功验证 返回当前用户信息
	hhcLoginFailure,		//登录失败
	hchGetRoomSort,			//客户端请求小盲注分类
	hhcSortedRoom,			//小盲注分类
	hchGetRoomList,			//客户端请求一种房间列表
	hhcRoomList,			//返回房间列表
	hchGetRoomInfo,			//客户端获取单一房间详细信息
	hhcRoomInfo,			//返回房间信息
	hchEnterRoom,			//进入房间
	hhcEnterRoomSuccess,	//进入成功
	hhcEnterRoomFailure,	//进入失败

	hchGetGameInfo,			//获取游戏状态
	hhcReflashGameInfo,		//刷新游戏状态

	hMax
} client_server_enum;
/*****************************************************/
///////////////////////////////////////////////////////
//       Structures sent from CLIENT to SERVER       //
///////////////////////////////////////////////////////

//1.登录请求信息
///cmdId = hchLogin;
typedef struct
{
	char	usrName[33];		//用户登录名
	char	usrPWD[33];			//用户密码
	char	ClientType[8];		//客户端种类
	char	ClientVersion[8];	//客户端版本
}GetUsrInfo,*PGetUsrInfo;		//用户登录帐户信息
///////////////////////////////////////////////////////


//2.小盲注请求信息
///cmdId = hchGetRoomSort;
//non struct
///////////////////////////////////////////////////////


//3.房间列表请求信息
///cmdId = hchGetRoomList;
typedef struct
{
	int		smallblind;			
	int		maxPlayer;
	bool	isVip;
	bool	isFastSpeed;
	bool	isFull;				//isHoldHallRoom;???
}GetRoomList,*PGetRoomList;
///////////////////////////////////////////////////////

//4.单一房间请求信息
///cmdId = hhchGetRoomInfo;
typedef struct
{
	int roomId;
}	GetRoomInfo,EnterRoom;

//5.进入房间请求信息
///cmdId = hchEnterRoom;

//EnterRoom struct

///////////////////////////////////////////////////////
/*****************************************************/

///////////////////////////////////////////////////////
//      Structures sent from SERVER to CLIENT        //
///////////////////////////////////////////////////////
typedef struct
{
	int itemCount;
	
}RoomUsrInfoCount,RoomSortInfoCount;
//1.登录返回信息
///cmdId = hhcLoginSuccess;
typedef struct
{
	int		usrID;				//用户ID
	char	usrNick[65];		//用户昵称
	int		usrExperience;		//用户经验
	int		usrCoins;			//用户金币
	long long	usrCounters;	//用户筹码
	char	usrInfo[256];		//额外信息json
}	UsrInfo,*PUsrInfo;			//登录验证返回的用户信息

///cmdId = hhcLoginFailure;
typedef struct
{
	short	errorCode;			//错误原因，0：账号密码错误，1:客户端版本过低.....		
}	LoginErrorInfo;				//登录失败，返回失败原因

///////////////////////////////////////////////////////

//2.小盲注返回信息
///cmdId = hhcSortedRoom;

typedef struct
{
	long long smallblind;
}	RoomSortInfo,*PRoomSortInfo;
///////////////////////////////////////////////////////

//3.房间列表返回信息
///cmdId = hhcRoomList;

//数量 = [socket readInt];
typedef struct
{
	int		roomId;
	long long	smallblind;			//小盲
	long long		ante;				//底注
	int		maxPlayer;			//桌面几个人
	bool	isVip;				//是否是VIP
	bool	isFastSpeed;		//快速
	int		playerCount;		//当前玩家个数
}	RoomInfo,*PRoomInfo;
///////////////////////////////////////////////////////

//4.单一房间返回信息
///cmdId = hhcRoomInfo;

typedef struct
{
	int		usrId;
	char	usrNick[65];		//用户昵称
	int		usrLevel;			//用户级别
	long long	usrCounters;	//用户筹码
	char	usrInfo[256];		//用户额外信息json
	int		position;			//用户所在桌面的位置
	
}	RoomUsrInfo,*PRoomUsrInfo;	//当前房间用户玩家信息
///////////////////////////////////////////////////////

//5.进入房间返回信息
//cmdId = hhcEnterRoomSuccess;

//返回单一房间返回信息

//cmdId = hhcEnterRoomFailure;
typedef struct
{
	short	errorCode;
}EnterRoomErrorInfo;			//返回失败原因
///////////////////////////////////////////////////////

//6.开始游戏返回信息
//cmdId = hhcReflashGameInfo;

typedef struct
{
	short state;		//当前状态
	//0未开始 1小盲注 2大盲注 
	//11等待第一轮下注 12等待第二轮下注 13等待第三轮下注 14等待第四轮下注
	//20结果

	short turn;					//当前玩家
	short dealerSeat;			//D位置
	short boardCardsNum;		//公共牌数
	short boardCards[5];		//公共牌


	int   money[10];			//玩家剩下的筹码数
	int   stake[10];			//赌注(玩家当前轮所下的筹码数，即摆在玩家面前的筹码数)
	short potNum;				//彩池个数
	int   pot[10];				//彩池

	bool  playing[9];			//是否在玩
	bool  allin[9];				//是否全进
	char  lastCommand[9];		//玩家的动作 0Null 1post 2fold 3check 4bet 5call 6raise 7胜利
	int   lastMaxMoney;			//上一轮最大的注
	
}UpdateDesk;

typedef struct 
{

	char  butId;  // 1fold 2check 3bet 4call 5raise 
	int   butNum;  //筹码数
}ClientCommand;


typedef struct 
{

	char  butId;  //按钮代号 0fold/check 2foldAny 3check 4check/callany 5callnow 6callany//-1取消勾 
	int   butNum;  //筹码数
}SetAutoCommand;







#pragma pack(pop)
//typedef struct
//{
//	int roomId;
//}	EnterRoomSuccess;
///////////////////////////////////////////////////////
/*****************************************************/

/* ********************for the ios****************** */
#ifdef ios_version
#include <CoreGraphics/CGBase.h>
///////////////////////////////////////////////////////
typedef struct
{
	int msgVer;
	int msgLen;
	int cmdId;
}	MessageHeader;

CG_INLINE MessageHeader
NewHeader(int Ver,int Len,int Id)
{
	MessageHeader msg;
	msg.msgVer = Ver;
	msg.msgLen = Len;
	msg.cmdId = Id;
	return msg;
}
///////////////////////////////////////////////////////
CG_INLINE GetUsrInfo
NewAccount(NSData *userName,NSData *userPSW)
{
	GetUsrInfo ua;
	size_t userNameLen = [userName length]> sizeof(ua.usrName) -1?sizeof(ua.usrName) -1:[userName length];
	size_t userPSWLen = [userPSW length]> sizeof(ua.usrPWD) -1?sizeof(ua.usrPWD) -1:[userPSW length];
		
	memcpy(ua.usrName,[userName bytes],userNameLen);
	ua.usrName[userNameLen] = 0;
	
	memcpy(ua.usrPWD,[userPSW bytes],userPSWLen);
	ua.usrPWD[userPSWLen] = 0;
	
	//show result

	printf("usrName:%s\n",ua.usrName);
	printf("usrPSW:%s\n",ua.usrPWD);
	
	return ua;
}
///////////////////////////////////////////////////////
CG_INLINE UsrInfo
NewUsrInfo(PUsrInfo uip)
{
	UsrInfo ui;
//	memset(&ui,0,sizeof(UsrInfo));
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	memcpy(&ui,uip,sizeof(UsrInfo));
	
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	
	return ui;
}
CG_INLINE int
SizeofUnichar(unichar * source)
{
	int i=0;
	for (; *(source+i); i++) {	
	}
	return i;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomSortInfo * sortedRoom;
	int num;

}	RoomSort,*PRoomSort;// for the client and not for the server
CG_INLINE RoomSort
NewRoomSort (RoomSortInfo * sorted,int num)
{
	RoomSort rs;
	rs.sortedRoom = sorted;
	rs.num = num;
	return rs;
}
///////////////////////////////////////////////////////

CG_INLINE RoomInfo
NewRoomInfo(PRoomInfo rip)
{
	RoomInfo ri;
	memcpy(&ri,rip,sizeof(RoomInfo));
	return ri;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomInfo * room;
	int num;
}	RoomList,PRoomList;
CG_INLINE RoomList
NewRoomList(PRoomInfo ri,int num)
{
	RoomList rl;
	rl.room = ri;
	rl.num = num;
	return rl;
}
CG_INLINE RoomList
NewRoomListNon()
{
	RoomList rl;
	rl.room = NULL;
	rl.num = 0;
	return rl;
}
///////////////////////////////////////////////////////

#endif
